import request from '@/utils/request'
export interface DefaultKeywordData {
  keyword: string
  schemeUrl: string
  highlight: number | string
  hidden: number | string
  type: number | string
  algSort: boolean | string
  extra: {
    resource: {
      materialName: string
      resourcesId: number | string
      materialId: number | string
    }
  }
}

export interface HotKeywordVOListData {
  keyword: string
  schemeUrl: string
  highlight: number | string
  hidden: number | string
  type: number | string
  algSort: boolean | string
  extra: {
    resource: {
      materialContentFrom: number | string
      rcmdSort: boolean | string
      taskType: number | string
      alg_personalized: string
      itemFrom: number | string
      resourcesId: number | string
    }
  }
}

export interface SearchKeywordData {
  data: {
    defaultKeyword: DefaultKeywordData
    defaultKeywords: DefaultKeywordData[]
    hotKeywordVOList: HotKeywordVOListData[]
    colorfulEggList: []
  }
  code: string
}

export interface SearchAutoData {
  data: string[]
  code: string
}

export default {
  getSearchKeywordData() {
    return request.get<any, SearchKeywordData>('/xhr/search/init.json')
  },
  getSearchAutoData(params: string) {
    return request.post<any, SearchAutoData>(`/xhr/search/searchAutoComplete.json?keywordPrefix=${params}`)
  },
  getSearchDetailData(keyword: string, id: number = 0) {
    return request.get(
      `/xhr/search/search.json?__timestamp=1630133434953&needPopWindow=true&searchWordSource=7&stillSearch=false&_stat_search=autoComplete&itemId=0&size=40&upperPrice=-1&floorPrice=-1&matchType=0&categoryId=${id}&descSorted=false&sortType=0&keyword=${keyword}`
    )
  }
}
